﻿// <copyright file="Video.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2008-09-23</date>
// <summary>MySpace Video</summary>

namespace MyOpenSpace
{
    using System;
    using System.Globalization;
    using System.Windows.Browser;
    using System.Windows.Media.Imaging;
    using Synergist;

    /// <summary>
    /// MySpace Video
    /// </summary>
    public class Video
    {
        /// <summary>
        /// Initializes a new instance of the Video class
        /// </summary>
        public Video()
        {
        }

        /// <summary>
        /// Initializes a new instance of the Video class
        /// </summary>
        /// <param name="video">video script object</param>
        public Video(ScriptObject video)
        {
            this.Country = video.getField("MyOpenSpace.Video.Field.COUNTRY") as string;
            this.DateCreated = video.GetDateField("MyOpenSpace.Video.Field.DATE_CREATED");
            this.Description = Uri.UnescapeDataString(video.getField("MyOpenSpace.Video.Field.DESCRIPTION") as string);
            this.Language = video.getField("MyOpenSpace.Video.Field.LANGUAGE") as string;
            this.LastUpdate = video.GetDateField("MyOpenSpace.Video.Field.LAST_UPDATE");
            this.MediaStatus = video.getField("MyOpenSpace.Video.Field.MEDIA_STATUS") as string;
            this.MediaType = int.Parse(video.getField("MyOpenSpace.Video.Field.MEDIA_TYPE") as string, CultureInfo.InvariantCulture);
            this.RunTime = double.Parse(video.getField("MyOpenSpace.Video.Field.RUN_TIME") as string, CultureInfo.InvariantCulture);
            this.ThumbImage = video.GetImageField("MyOpenSpace.Video.Field.THUMB_URI");
            this.Title = video.getField("MyOpenSpace.Video.Field.TITLE") as string;
            this.TotalComments = int.Parse(video.getField("MyOpenSpace.Video.Field.TOTAL_COMMENTS") as string, CultureInfo.InvariantCulture);
            this.TotalRatings = int.Parse(video.getField("MyOpenSpace.Video.Field.TOTAL_RATING") as string, CultureInfo.InvariantCulture);
            this.TotalViews = int.Parse(video.getField("MyOpenSpace.Video.Field.TOTAL_VIEWS") as string, CultureInfo.InvariantCulture);
            this.TotalVotes = int.Parse(video.getField("MyOpenSpace.Video.Field.TOTAL_VOTES") as string, CultureInfo.InvariantCulture);
            this.VideoID = System.Convert.ToInt32((double)video.getField("MyOpenSpace.Video.Field.VIDEO_ID"));
            this.VideoUri = video.GetUriField("MyOpenSpace.Video.Field.VIDEO_URI");
        }

        /// <summary>
        /// Gets or sets the title of the video
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets the description
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// Gets or sets the last update date
        /// </summary>
        public DateTime? LastUpdate { get; set; }

        /// <summary>
        /// Gets or sets the media ID
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "ID", Justification = "Mirroring OpenSocial API.")]
        public int VideoID { get; set; }

        /// <summary>
        /// Gets or sets the video URL
        /// </summary>
        public Uri VideoUri { get; set; }

        /// <summary>
        /// Gets or sets the date created
        /// </summary>
        public DateTime? DateCreated { get; set; }

        /// <summary>
        /// Gets or setsthe media type: 4 is video
        /// </summary>
        public int MediaType { get; set; }

        /// <summary>
        /// Gets or sets the Thumbnail image (use this for Image.Source)
        /// </summary>
        public BitmapImage ThumbImage { get; set; }

        /// <summary>
        /// Gets or sets the media status
        /// </summary>
        public string MediaStatus { get; set; }

        /// <summary>
        /// Gets or sets the run time in seconds
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "RunTime", Justification = "This is the Run time of the video.")]
        public double RunTime { get; set; }

        /// <summary>
        /// Gets or sets the total number of views
        /// </summary>
        public int TotalViews { get; set; }

        /// <summary>
        /// Gets or sets the total number of comments
        /// </summary>
        public int TotalComments { get; set; }

        /// <summary>
        /// Gets or sets the total number of ratings
        /// </summary>
        public int TotalRatings { get; set; }

        /// <summary>
        /// Gets or sets the total number of votes
        /// </summary>
        public int TotalVotes { get; set; }

        /// <summary>
        /// Gets or sets the country of the video
        /// </summary>
        public string Country { get; set; }

        /// <summary>
        /// Gets or sets the language of the video
        /// </summary>
        public string Language { get; set; }

        /// <summary>
        /// Get the properties for the video
        /// </summary>
        /// <returns>all of the properties and their values.</returns>
        public override string ToString()
        {
            return Synergist.Utility.GetProperties(this);
        }
    }
}
